package com.visionet.waveletData.web.common.utilities.collection;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

public class CollectionUtil {

    public static <T> List<T> toList(String str,String split,Class<T> destinationClass){
        if(str==null||str.isEmpty()) return null;

        List list = new ArrayList<T>();

        String[] array = str.split(split);
        for(String temp:array){
            if(destinationClass == Long.class){
                list.add(Long.parseLong(temp));
            }else if(destinationClass == Integer.class){
                list.add(Integer.parseInt(temp));
            }else{
                list.add(temp);
            }

        }
        return list;
    }

    public static List<String> toList(String str,String split){
        return (List<String>)toList(str,split,String.class);
    }

    public static List invertList(List list){
        List inverts = Lists.newArrayList();
        for(int i=list.size()-1;i>=0;i--){
            inverts.add(list.get(i));
        }
        return inverts;
    }


}
